{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Pandas 查询数据"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Pandas查询数据的几种方法\n",
    "1.df.loc方法，根据行、列的标签值查询<br>\n",
    "2.df.iloc方法，根据行列的数字位置查询<br>\n",
    "3.df.where方法<br>\n",
    "4.df.query方法"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "loc既能查询，又能覆盖写入，强烈推荐！"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Pandas使用df.loc查询数据的方法"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1.使用单个`label`值查询数据<br>\n",
    "2.使用值列表批量查询<br>\n",
    "3.使用数值区间进行范围查询<br>\n",
    "4.使用条件表达式查询<br>\n",
    "5.调用函数查询"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 注意\n",
    "* 以上查询方法，既适用于行，也适用于列\n",
    "* 注意观察降维`dataFrame`->`Series`->值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 0. 读取数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.read_csv(\"datas/weather_20230115134249.csv\", encoding='utf-8')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>日期</th>\n",
       "      <th>城市</th>\n",
       "      <th>行政区</th>\n",
       "      <th>观测站</th>\n",
       "      <th>气温(度)</th>\n",
       "      <th>相对湿度(%)</th>\n",
       "      <th>累积雨量(mm)</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2015-01-01</td>\n",
       "      <td>新北市</td>\n",
       "      <td>烏來區</td>\n",
       "      <td>福山</td>\n",
       "      <td>13.7℃</td>\n",
       "      <td>92</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2015-01-02</td>\n",
       "      <td>臺南市</td>\n",
       "      <td>安平區</td>\n",
       "      <td>安平</td>\n",
       "      <td>23.5℃</td>\n",
       "      <td>70</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2015-01-03</td>\n",
       "      <td>臺東縣</td>\n",
       "      <td>東河鄉</td>\n",
       "      <td>七塊厝</td>\n",
       "      <td>19.6℃</td>\n",
       "      <td>86</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2015-01-04</td>\n",
       "      <td>新北市</td>\n",
       "      <td>貢寮區</td>\n",
       "      <td>福隆</td>\n",
       "      <td>14.2℃</td>\n",
       "      <td>96</td>\n",
       "      <td>-99.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2015-01-05</td>\n",
       "      <td>南投縣</td>\n",
       "      <td>仁愛鄉</td>\n",
       "      <td>小奇萊</td>\n",
       "      <td>8.3℃</td>\n",
       "      <td>57</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           日期   城市  行政区  观测站  气温(度)  相对湿度(%)  累积雨量(mm)\n",
       "0  2015-01-01  新北市  烏來區   福山  13.7℃       92       0.0\n",
       "1  2015-01-02  臺南市  安平區   安平  23.5℃       70       0.0\n",
       "2  2015-01-03  臺東縣  東河鄉  七塊厝  19.6℃       86       0.0\n",
       "3  2015-01-04  新北市  貢寮區   福隆  14.2℃       96     -99.0\n",
       "4  2015-01-05  南投縣  仁愛鄉  小奇萊   8.3℃       57       0.0"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 设定索引为日期，方便日期筛选\n",
    "df.set_index('日期',inplace=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['2015-01-01', '2015-01-02', '2015-01-03', '2015-01-04', '2015-01-05',\n",
       "       '2015-01-06', '2015-01-07', '2015-01-08', '2015-01-09', '2015-01-10',\n",
       "       ...\n",
       "       '2016-04-19', '2016-04-20', '2016-04-21', '2016-04-22', '2016-04-23',\n",
       "       '2016-04-24', '2016-04-25', '2016-04-26', '2016-04-27', '2016-04-28'],\n",
       "      dtype='object', name='日期', length=484)"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "df.loc[:,\"气温(度)\"]=df[\"气温(度)\"].str.replace(\"℃\",\"\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "城市           object\n",
       "行政区          object\n",
       "观测站          object\n",
       "气温(度)        object\n",
       "相对湿度(%)       int64\n",
       "累积雨量(mm)    float64\n",
       "dtype: object"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.dtypes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>城市</th>\n",
       "      <th>行政区</th>\n",
       "      <th>观测站</th>\n",
       "      <th>气温(度)</th>\n",
       "      <th>相对湿度(%)</th>\n",
       "      <th>累积雨量(mm)</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>日期</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2015-01-01</th>\n",
       "      <td>新北市</td>\n",
       "      <td>烏來區</td>\n",
       "      <td>福山</td>\n",
       "      <td>13.7</td>\n",
       "      <td>92</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-02</th>\n",
       "      <td>臺南市</td>\n",
       "      <td>安平區</td>\n",
       "      <td>安平</td>\n",
       "      <td>23.5</td>\n",
       "      <td>70</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-03</th>\n",
       "      <td>臺東縣</td>\n",
       "      <td>東河鄉</td>\n",
       "      <td>七塊厝</td>\n",
       "      <td>19.6</td>\n",
       "      <td>86</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-04</th>\n",
       "      <td>新北市</td>\n",
       "      <td>貢寮區</td>\n",
       "      <td>福隆</td>\n",
       "      <td>14.2</td>\n",
       "      <td>96</td>\n",
       "      <td>-99.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-05</th>\n",
       "      <td>南投縣</td>\n",
       "      <td>仁愛鄉</td>\n",
       "      <td>小奇萊</td>\n",
       "      <td>8.3</td>\n",
       "      <td>57</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "             城市  行政区  观测站 气温(度)  相对湿度(%)  累积雨量(mm)\n",
       "日期                                                \n",
       "2015-01-01  新北市  烏來區   福山  13.7       92       0.0\n",
       "2015-01-02  臺南市  安平區   安平  23.5       70       0.0\n",
       "2015-01-03  臺東縣  東河鄉  七塊厝  19.6       86       0.0\n",
       "2015-01-04  新北市  貢寮區   福隆  14.2       96     -99.0\n",
       "2015-01-05  南投縣  仁愛鄉  小奇萊   8.3       57       0.0"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1. 使用单个label值查询数据\n",
    "行或者列，都可以只传入单个值，实现精确匹配"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'13.5'"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 得到单个值\n",
    "df.loc['2015-05-12','气温(度)']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "气温(度)      13.5\n",
       "相对湿度(%)      81\n",
       "Name: 2015-05-12, dtype: object"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 得到一个Series\n",
    "df.loc['2015-05-12',['气温(度)','相对湿度(%)']]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2. 使用值列表批量查询"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "日期\n",
       "2015-05-12    13.5\n",
       "2015-10-10    22.1\n",
       "Name: 气温(度), dtype: object"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 得到Series\n",
    "df.loc[['2015-05-12','2015-10-10'],'气温(度)']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>气温(度)</th>\n",
       "      <th>相对湿度(%)</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>日期</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2015-05-12</th>\n",
       "      <td>13.5</td>\n",
       "      <td>81</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-10-10</th>\n",
       "      <td>22.1</td>\n",
       "      <td>60</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           气温(度)  相对湿度(%)\n",
       "日期                       \n",
       "2015-05-12  13.5       81\n",
       "2015-10-10  22.1       60"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 得到DataFrame\n",
    "df.loc[['2015-05-12','2015-10-10'],['气温(度)','相对湿度(%)']]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 3. 使用数值区间进行范围查询\n",
    "注意：区间既包含开始，也包含结束"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "日期\n",
       "2015-05-12    13.5\n",
       "2015-05-13     -99\n",
       "Name: 气温(度), dtype: object"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 行index按区间\n",
    "df.loc['2015-05-12':'2015-05-13','气温(度)']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "气温(度)       22.1\n",
       "相对湿度(%)       60\n",
       "累积雨量(mm)       0\n",
       "Name: 2015-10-10, dtype: object"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 列index按区间\n",
    "df.loc['2015-10-10','气温(度)':'累积雨量(mm)']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>气温(度)</th>\n",
       "      <th>相对湿度(%)</th>\n",
       "      <th>累积雨量(mm)</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>日期</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2015-05-12</th>\n",
       "      <td>13.5</td>\n",
       "      <td>81</td>\n",
       "      <td>6.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-05-13</th>\n",
       "      <td>-99</td>\n",
       "      <td>-9900</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           气温(度)  相对湿度(%)  累积雨量(mm)\n",
       "日期                                 \n",
       "2015-05-12  13.5       81       6.0\n",
       "2015-05-13   -99    -9900       0.0"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 行和列都按区间查询\n",
    "df.loc['2015-05-12':'2015-05-13','气温(度)':'累积雨量(mm)']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 4. 使用条件表达式查询\n",
    "boolean列表的长度得等于行数或者列数"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**简单条件查询，最低温度低于-10度的列表**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>城市</th>\n",
       "      <th>行政区</th>\n",
       "      <th>观测站</th>\n",
       "      <th>气温(度)</th>\n",
       "      <th>相对湿度(%)</th>\n",
       "      <th>累积雨量(mm)</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>日期</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2015-01-16</th>\n",
       "      <td>苗栗縣</td>\n",
       "      <td>造橋鄉</td>\n",
       "      <td>造橋</td>\n",
       "      <td>-99</td>\n",
       "      <td>-9900</td>\n",
       "      <td>-99.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-25</th>\n",
       "      <td>臺中市</td>\n",
       "      <td>西屯區</td>\n",
       "      <td>西屯</td>\n",
       "      <td>-99</td>\n",
       "      <td>-9900</td>\n",
       "      <td>-99.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-02-22</th>\n",
       "      <td>南投縣</td>\n",
       "      <td>仁愛鄉</td>\n",
       "      <td>奇萊稜線A</td>\n",
       "      <td>-99</td>\n",
       "      <td>-9900</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-05-13</th>\n",
       "      <td>臺南市</td>\n",
       "      <td>西港區</td>\n",
       "      <td>西港</td>\n",
       "      <td>-99</td>\n",
       "      <td>-9900</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-06-08</th>\n",
       "      <td>屏東縣</td>\n",
       "      <td>新埤鄉</td>\n",
       "      <td>新埤</td>\n",
       "      <td>-99</td>\n",
       "      <td>-9900</td>\n",
       "      <td>-99.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-06-11</th>\n",
       "      <td>新北市</td>\n",
       "      <td>瑞芳區</td>\n",
       "      <td>鼻頭角</td>\n",
       "      <td>-99</td>\n",
       "      <td>-9900</td>\n",
       "      <td>0.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-06-12</th>\n",
       "      <td>臺中市</td>\n",
       "      <td>烏日區</td>\n",
       "      <td>烏日</td>\n",
       "      <td>-99</td>\n",
       "      <td>-9900</td>\n",
       "      <td>-99.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-07-06</th>\n",
       "      <td>新北市</td>\n",
       "      <td>汐止區</td>\n",
       "      <td>汐止</td>\n",
       "      <td>-99</td>\n",
       "      <td>-9900</td>\n",
       "      <td>-99.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-01-17</th>\n",
       "      <td>高雄市</td>\n",
       "      <td>梓官區</td>\n",
       "      <td>梓官</td>\n",
       "      <td>-99</td>\n",
       "      <td>-9900</td>\n",
       "      <td>-99.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-03-29</th>\n",
       "      <td>屏東縣</td>\n",
       "      <td>長治鄉</td>\n",
       "      <td>長治</td>\n",
       "      <td>-99</td>\n",
       "      <td>-9900</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-04-15</th>\n",
       "      <td>新北市</td>\n",
       "      <td>永和區</td>\n",
       "      <td>永和</td>\n",
       "      <td>-99</td>\n",
       "      <td>-9900</td>\n",
       "      <td>-99.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "             城市  行政区    观测站 气温(度)  相对湿度(%)  累积雨量(mm)\n",
       "日期                                                  \n",
       "2015-01-16  苗栗縣  造橋鄉     造橋   -99    -9900     -99.0\n",
       "2015-01-25  臺中市  西屯區     西屯   -99    -9900     -99.0\n",
       "2015-02-22  南投縣  仁愛鄉  奇萊稜線A   -99    -9900       0.0\n",
       "2015-05-13  臺南市  西港區     西港   -99    -9900       0.0\n",
       "2015-06-08  屏東縣  新埤鄉     新埤   -99    -9900     -99.0\n",
       "2015-06-11  新北市  瑞芳區    鼻頭角   -99    -9900       0.5\n",
       "2015-06-12  臺中市  烏日區     烏日   -99    -9900     -99.0\n",
       "2015-07-06  新北市  汐止區     汐止   -99    -9900     -99.0\n",
       "2016-01-17  高雄市  梓官區     梓官   -99    -9900     -99.0\n",
       "2016-03-29  屏東縣  長治鄉     長治   -99    -9900       0.0\n",
       "2016-04-15  新北市  永和區     永和   -99    -9900     -99.0"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc[df[\"气温(度)\"].astype(float)<-10,:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "日期\n",
       "2015-01-01    False\n",
       "2015-01-02    False\n",
       "2015-01-03    False\n",
       "2015-01-04    False\n",
       "2015-01-05    False\n",
       "2015-01-06    False\n",
       "2015-01-07    False\n",
       "2015-01-08    False\n",
       "2015-01-09    False\n",
       "2015-01-10    False\n",
       "2015-01-11    False\n",
       "2015-01-12    False\n",
       "2015-01-13    False\n",
       "2015-01-14    False\n",
       "2015-01-15    False\n",
       "2015-01-16     True\n",
       "2015-01-17    False\n",
       "2015-01-18    False\n",
       "2015-01-19    False\n",
       "2015-01-20    False\n",
       "2015-01-21    False\n",
       "2015-01-22    False\n",
       "2015-01-23    False\n",
       "2015-01-24    False\n",
       "2015-01-25     True\n",
       "2015-01-26    False\n",
       "2015-01-27    False\n",
       "2015-01-28    False\n",
       "2015-01-29    False\n",
       "2015-01-30    False\n",
       "              ...  \n",
       "2016-03-30    False\n",
       "2016-03-31    False\n",
       "2016-04-01    False\n",
       "2016-04-02    False\n",
       "2016-04-03    False\n",
       "2016-04-04    False\n",
       "2016-04-05    False\n",
       "2016-04-06    False\n",
       "2016-04-07    False\n",
       "2016-04-08    False\n",
       "2016-04-09    False\n",
       "2016-04-10    False\n",
       "2016-04-11    False\n",
       "2016-04-12    False\n",
       "2016-04-13    False\n",
       "2016-04-14    False\n",
       "2016-04-15     True\n",
       "2016-04-16    False\n",
       "2016-04-17    False\n",
       "2016-04-18    False\n",
       "2016-04-19    False\n",
       "2016-04-20    False\n",
       "2016-04-21    False\n",
       "2016-04-22    False\n",
       "2016-04-23    False\n",
       "2016-04-24    False\n",
       "2016-04-25    False\n",
       "2016-04-26    False\n",
       "2016-04-27    False\n",
       "2016-04-28    False\n",
       "Name: 气温(度), Length: 484, dtype: bool"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 观察一些这里的boolean条件\n",
    "df[\"气温(度)\"].astype(float)<-10"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**复杂查询条件，查一下我心中的目标天气**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>城市</th>\n",
       "      <th>行政区</th>\n",
       "      <th>观测站</th>\n",
       "      <th>气温(度)</th>\n",
       "      <th>相对湿度(%)</th>\n",
       "      <th>累积雨量(mm)</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>日期</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2015-01-02</th>\n",
       "      <td>臺南市</td>\n",
       "      <td>安平區</td>\n",
       "      <td>安平</td>\n",
       "      <td>23.5</td>\n",
       "      <td>70</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-03</th>\n",
       "      <td>臺東縣</td>\n",
       "      <td>東河鄉</td>\n",
       "      <td>七塊厝</td>\n",
       "      <td>19.6</td>\n",
       "      <td>86</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-06</th>\n",
       "      <td>嘉義縣</td>\n",
       "      <td>大林鎮</td>\n",
       "      <td>大林</td>\n",
       "      <td>23.2</td>\n",
       "      <td>63</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-07</th>\n",
       "      <td>花蓮縣</td>\n",
       "      <td>玉里鎮</td>\n",
       "      <td>玉里</td>\n",
       "      <td>18.5</td>\n",
       "      <td>85</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-08</th>\n",
       "      <td>嘉義市</td>\n",
       "      <td>東區</td>\n",
       "      <td>嘉義市東區</td>\n",
       "      <td>25</td>\n",
       "      <td>64</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-11</th>\n",
       "      <td>彰化縣</td>\n",
       "      <td>大城鄉</td>\n",
       "      <td>三豐</td>\n",
       "      <td>17.4</td>\n",
       "      <td>81</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-12</th>\n",
       "      <td>雲林縣</td>\n",
       "      <td>斗六市</td>\n",
       "      <td>斗六</td>\n",
       "      <td>23</td>\n",
       "      <td>58</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-13</th>\n",
       "      <td>南投縣</td>\n",
       "      <td>魚池鄉</td>\n",
       "      <td>魚池</td>\n",
       "      <td>26.3</td>\n",
       "      <td>50</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-14</th>\n",
       "      <td>臺東縣</td>\n",
       "      <td>海端鄉</td>\n",
       "      <td>向陽</td>\n",
       "      <td>16.3</td>\n",
       "      <td>71</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-15</th>\n",
       "      <td>屏東縣</td>\n",
       "      <td>竹田鄉</td>\n",
       "      <td>竹田</td>\n",
       "      <td>26.7</td>\n",
       "      <td>80</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-18</th>\n",
       "      <td>苗栗縣</td>\n",
       "      <td>頭屋鄉</td>\n",
       "      <td>明德</td>\n",
       "      <td>17</td>\n",
       "      <td>65</td>\n",
       "      <td>-99.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-19</th>\n",
       "      <td>臺南市</td>\n",
       "      <td>下營區</td>\n",
       "      <td>下營</td>\n",
       "      <td>26.2</td>\n",
       "      <td>58</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-20</th>\n",
       "      <td>屏東縣</td>\n",
       "      <td>萬丹鄉</td>\n",
       "      <td>萬丹</td>\n",
       "      <td>27</td>\n",
       "      <td>62</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-21</th>\n",
       "      <td>新北市</td>\n",
       "      <td>三峽區</td>\n",
       "      <td>三峽</td>\n",
       "      <td>16.5</td>\n",
       "      <td>67</td>\n",
       "      <td>-99.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-23</th>\n",
       "      <td>彰化縣</td>\n",
       "      <td>大城鄉</td>\n",
       "      <td>大城</td>\n",
       "      <td>19.2</td>\n",
       "      <td>72</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-24</th>\n",
       "      <td>臺中市</td>\n",
       "      <td>大里區</td>\n",
       "      <td>大里</td>\n",
       "      <td>24.3</td>\n",
       "      <td>50</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-26</th>\n",
       "      <td>臺東縣</td>\n",
       "      <td>鹿野鄉</td>\n",
       "      <td>鹿野</td>\n",
       "      <td>18.2</td>\n",
       "      <td>85</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-27</th>\n",
       "      <td>嘉義縣</td>\n",
       "      <td>太保市</td>\n",
       "      <td>太保</td>\n",
       "      <td>23.9</td>\n",
       "      <td>61</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-28</th>\n",
       "      <td>臺南市</td>\n",
       "      <td>學甲區</td>\n",
       "      <td>學甲</td>\n",
       "      <td>22.2</td>\n",
       "      <td>66</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-29</th>\n",
       "      <td>屏東縣</td>\n",
       "      <td>新園鄉</td>\n",
       "      <td>新園</td>\n",
       "      <td>25.4</td>\n",
       "      <td>76</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-31</th>\n",
       "      <td>臺中市</td>\n",
       "      <td>清水區</td>\n",
       "      <td>清水</td>\n",
       "      <td>17.8</td>\n",
       "      <td>80</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-02-01</th>\n",
       "      <td>臺南市</td>\n",
       "      <td>新化區</td>\n",
       "      <td>虎頭埤</td>\n",
       "      <td>26.1</td>\n",
       "      <td>67</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-02-02</th>\n",
       "      <td>臺中市</td>\n",
       "      <td>石岡區</td>\n",
       "      <td>石岡</td>\n",
       "      <td>19.4</td>\n",
       "      <td>99</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-02-03</th>\n",
       "      <td>屏東縣</td>\n",
       "      <td>枋山鄉</td>\n",
       "      <td>枋山</td>\n",
       "      <td>25.1</td>\n",
       "      <td>67</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-02-04</th>\n",
       "      <td>屏東縣</td>\n",
       "      <td>滿州鄉</td>\n",
       "      <td>滿州</td>\n",
       "      <td>22.6</td>\n",
       "      <td>79</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-02-05</th>\n",
       "      <td>屏東縣</td>\n",
       "      <td>恆春鎮</td>\n",
       "      <td>墾雷</td>\n",
       "      <td>23.6</td>\n",
       "      <td>82</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-02-07</th>\n",
       "      <td>臺東縣</td>\n",
       "      <td>卑南鄉</td>\n",
       "      <td>檳榔四格山</td>\n",
       "      <td>18.8</td>\n",
       "      <td>88</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-02-08</th>\n",
       "      <td>嘉義縣</td>\n",
       "      <td>六腳鄉</td>\n",
       "      <td>六腳</td>\n",
       "      <td>22.3</td>\n",
       "      <td>67</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-02-09</th>\n",
       "      <td>雲林縣</td>\n",
       "      <td>斗南鎮</td>\n",
       "      <td>斗南</td>\n",
       "      <td>22.5</td>\n",
       "      <td>64</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-02-10</th>\n",
       "      <td>臺南市</td>\n",
       "      <td>北區</td>\n",
       "      <td>臺南市北區</td>\n",
       "      <td>24.7</td>\n",
       "      <td>66</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-03-23</th>\n",
       "      <td>雲林縣</td>\n",
       "      <td>水林鄉</td>\n",
       "      <td>水林</td>\n",
       "      <td>20.9</td>\n",
       "      <td>69</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-03-25</th>\n",
       "      <td>高雄市</td>\n",
       "      <td>茄萣區</td>\n",
       "      <td>茄萣</td>\n",
       "      <td>23.1</td>\n",
       "      <td>76</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-03-26</th>\n",
       "      <td>宜蘭縣</td>\n",
       "      <td>冬山鄉</td>\n",
       "      <td>冬山</td>\n",
       "      <td>17</td>\n",
       "      <td>93</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-03-27</th>\n",
       "      <td>宜蘭縣</td>\n",
       "      <td>礁溪鄉</td>\n",
       "      <td>礁溪</td>\n",
       "      <td>17.6</td>\n",
       "      <td>71</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-03-28</th>\n",
       "      <td>屏東縣</td>\n",
       "      <td>里港鄉</td>\n",
       "      <td>里港</td>\n",
       "      <td>27.8</td>\n",
       "      <td>66</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-03-30</th>\n",
       "      <td>臺南市</td>\n",
       "      <td>白河區</td>\n",
       "      <td>鹿寮</td>\n",
       "      <td>23</td>\n",
       "      <td>74</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-03-31</th>\n",
       "      <td>宜蘭縣</td>\n",
       "      <td>壯圍鄉</td>\n",
       "      <td>大福</td>\n",
       "      <td>17.3</td>\n",
       "      <td>79</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-04-01</th>\n",
       "      <td>臺東縣</td>\n",
       "      <td>達仁鄉</td>\n",
       "      <td>達仁林場</td>\n",
       "      <td>17.9</td>\n",
       "      <td>97</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-04-02</th>\n",
       "      <td>雲林縣</td>\n",
       "      <td>東勢鄉</td>\n",
       "      <td>雲林東勢</td>\n",
       "      <td>19.9</td>\n",
       "      <td>71</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-04-03</th>\n",
       "      <td>屏東縣</td>\n",
       "      <td>牡丹鄉</td>\n",
       "      <td>四林格山</td>\n",
       "      <td>19.2</td>\n",
       "      <td>94</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-04-04</th>\n",
       "      <td>屏東縣</td>\n",
       "      <td>牡丹鄉</td>\n",
       "      <td>牡丹</td>\n",
       "      <td>22.8</td>\n",
       "      <td>79</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-04-05</th>\n",
       "      <td>嘉義縣</td>\n",
       "      <td>布袋鎮</td>\n",
       "      <td>布袋</td>\n",
       "      <td>21.4</td>\n",
       "      <td>69</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-04-06</th>\n",
       "      <td>南投縣</td>\n",
       "      <td>竹山鎮</td>\n",
       "      <td>竹山</td>\n",
       "      <td>24.6</td>\n",
       "      <td>66</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-04-07</th>\n",
       "      <td>高雄市</td>\n",
       "      <td>田寮區</td>\n",
       "      <td>古亭坑</td>\n",
       "      <td>26.4</td>\n",
       "      <td>67</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-04-10</th>\n",
       "      <td>屏東縣</td>\n",
       "      <td>鹽埔鄉</td>\n",
       "      <td>鹽埔</td>\n",
       "      <td>28.3</td>\n",
       "      <td>73</td>\n",
       "      <td>-99.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-04-11</th>\n",
       "      <td>臺東縣</td>\n",
       "      <td>臺東市</td>\n",
       "      <td>知本(水試所)</td>\n",
       "      <td>22.7</td>\n",
       "      <td>72</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-04-12</th>\n",
       "      <td>南投縣</td>\n",
       "      <td>中寮鄉</td>\n",
       "      <td>中寮</td>\n",
       "      <td>24.2</td>\n",
       "      <td>59</td>\n",
       "      <td>-99.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-04-13</th>\n",
       "      <td>臺南市</td>\n",
       "      <td>龍崎區</td>\n",
       "      <td>崎頂</td>\n",
       "      <td>25.1</td>\n",
       "      <td>75</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-04-14</th>\n",
       "      <td>苗栗縣</td>\n",
       "      <td>三義鄉</td>\n",
       "      <td>三義</td>\n",
       "      <td>15.3</td>\n",
       "      <td>91</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-04-16</th>\n",
       "      <td>屏東縣</td>\n",
       "      <td>來義鄉</td>\n",
       "      <td>白鷺</td>\n",
       "      <td>25.3</td>\n",
       "      <td>72</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-04-17</th>\n",
       "      <td>屏東縣</td>\n",
       "      <td>滿州鄉</td>\n",
       "      <td>佳樂水</td>\n",
       "      <td>24.1</td>\n",
       "      <td>75</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-04-18</th>\n",
       "      <td>臺南市</td>\n",
       "      <td>白河區</td>\n",
       "      <td>白河</td>\n",
       "      <td>23.4</td>\n",
       "      <td>68</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-04-19</th>\n",
       "      <td>新竹縣</td>\n",
       "      <td>峨眉鄉</td>\n",
       "      <td>峨眉</td>\n",
       "      <td>16.6</td>\n",
       "      <td>73</td>\n",
       "      <td>5.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-04-20</th>\n",
       "      <td>新北市</td>\n",
       "      <td>蘆洲區</td>\n",
       "      <td>蘆洲</td>\n",
       "      <td>17.6</td>\n",
       "      <td>71</td>\n",
       "      <td>-99.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-04-21</th>\n",
       "      <td>屏東縣</td>\n",
       "      <td>萬巒鄉</td>\n",
       "      <td>來義</td>\n",
       "      <td>26.8</td>\n",
       "      <td>69</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-04-22</th>\n",
       "      <td>新北市</td>\n",
       "      <td>三重區</td>\n",
       "      <td>三重</td>\n",
       "      <td>16.3</td>\n",
       "      <td>76</td>\n",
       "      <td>3.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-04-23</th>\n",
       "      <td>高雄市</td>\n",
       "      <td>茄萣區</td>\n",
       "      <td>興達</td>\n",
       "      <td>25.1</td>\n",
       "      <td>67</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-04-24</th>\n",
       "      <td>新北市</td>\n",
       "      <td>板橋區</td>\n",
       "      <td>板橋</td>\n",
       "      <td>15.6</td>\n",
       "      <td>73</td>\n",
       "      <td>5.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-04-26</th>\n",
       "      <td>花蓮縣</td>\n",
       "      <td>壽豐鄉</td>\n",
       "      <td>大坑</td>\n",
       "      <td>15.7</td>\n",
       "      <td>94</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-04-27</th>\n",
       "      <td>新竹縣</td>\n",
       "      <td>五峰鄉</td>\n",
       "      <td>雪霸</td>\n",
       "      <td>15.7</td>\n",
       "      <td>62</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>367 rows × 6 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "             城市  行政区      观测站 气温(度)  相对湿度(%)  累积雨量(mm)\n",
       "日期                                                    \n",
       "2015-01-02  臺南市  安平區       安平  23.5       70       0.0\n",
       "2015-01-03  臺東縣  東河鄉      七塊厝  19.6       86       0.0\n",
       "2015-01-06  嘉義縣  大林鎮       大林  23.2       63       0.0\n",
       "2015-01-07  花蓮縣  玉里鎮       玉里  18.5       85       0.0\n",
       "2015-01-08  嘉義市   東區    嘉義市東區    25       64       0.0\n",
       "2015-01-11  彰化縣  大城鄉       三豐  17.4       81       0.0\n",
       "2015-01-12  雲林縣  斗六市       斗六    23       58       0.0\n",
       "2015-01-13  南投縣  魚池鄉       魚池  26.3       50       0.0\n",
       "2015-01-14  臺東縣  海端鄉       向陽  16.3       71       0.0\n",
       "2015-01-15  屏東縣  竹田鄉       竹田  26.7       80       0.0\n",
       "2015-01-18  苗栗縣  頭屋鄉       明德    17       65     -99.0\n",
       "2015-01-19  臺南市  下營區       下營  26.2       58       0.0\n",
       "2015-01-20  屏東縣  萬丹鄉       萬丹    27       62       0.0\n",
       "2015-01-21  新北市  三峽區       三峽  16.5       67     -99.0\n",
       "2015-01-23  彰化縣  大城鄉       大城  19.2       72       0.0\n",
       "2015-01-24  臺中市  大里區       大里  24.3       50       0.0\n",
       "2015-01-26  臺東縣  鹿野鄉       鹿野  18.2       85       0.0\n",
       "2015-01-27  嘉義縣  太保市       太保  23.9       61       0.0\n",
       "2015-01-28  臺南市  學甲區       學甲  22.2       66       0.0\n",
       "2015-01-29  屏東縣  新園鄉       新園  25.4       76       0.0\n",
       "2015-01-31  臺中市  清水區       清水  17.8       80       0.0\n",
       "2015-02-01  臺南市  新化區      虎頭埤  26.1       67       0.0\n",
       "2015-02-02  臺中市  石岡區       石岡  19.4       99       0.0\n",
       "2015-02-03  屏東縣  枋山鄉       枋山  25.1       67       0.0\n",
       "2015-02-04  屏東縣  滿州鄉       滿州  22.6       79       0.0\n",
       "2015-02-05  屏東縣  恆春鎮       墾雷  23.6       82       0.0\n",
       "2015-02-07  臺東縣  卑南鄉    檳榔四格山  18.8       88       0.0\n",
       "2015-02-08  嘉義縣  六腳鄉       六腳  22.3       67       0.0\n",
       "2015-02-09  雲林縣  斗南鎮       斗南  22.5       64       0.0\n",
       "2015-02-10  臺南市   北區    臺南市北區  24.7       66       0.0\n",
       "...         ...  ...      ...   ...      ...       ...\n",
       "2016-03-23  雲林縣  水林鄉       水林  20.9       69       0.0\n",
       "2016-03-25  高雄市  茄萣區       茄萣  23.1       76       0.0\n",
       "2016-03-26  宜蘭縣  冬山鄉       冬山    17       93       0.0\n",
       "2016-03-27  宜蘭縣  礁溪鄉       礁溪  17.6       71       0.0\n",
       "2016-03-28  屏東縣  里港鄉       里港  27.8       66       0.0\n",
       "2016-03-30  臺南市  白河區       鹿寮    23       74       0.0\n",
       "2016-03-31  宜蘭縣  壯圍鄉       大福  17.3       79       0.0\n",
       "2016-04-01  臺東縣  達仁鄉     達仁林場  17.9       97       0.0\n",
       "2016-04-02  雲林縣  東勢鄉     雲林東勢  19.9       71       0.0\n",
       "2016-04-03  屏東縣  牡丹鄉     四林格山  19.2       94       0.0\n",
       "2016-04-04  屏東縣  牡丹鄉       牡丹  22.8       79       0.0\n",
       "2016-04-05  嘉義縣  布袋鎮       布袋  21.4       69       0.0\n",
       "2016-04-06  南投縣  竹山鎮       竹山  24.6       66       0.0\n",
       "2016-04-07  高雄市  田寮區      古亭坑  26.4       67       0.0\n",
       "2016-04-10  屏東縣  鹽埔鄉       鹽埔  28.3       73     -99.0\n",
       "2016-04-11  臺東縣  臺東市  知本(水試所)  22.7       72       0.0\n",
       "2016-04-12  南投縣  中寮鄉       中寮  24.2       59     -99.0\n",
       "2016-04-13  臺南市  龍崎區       崎頂  25.1       75       0.0\n",
       "2016-04-14  苗栗縣  三義鄉       三義  15.3       91       2.0\n",
       "2016-04-16  屏東縣  來義鄉       白鷺  25.3       72       0.0\n",
       "2016-04-17  屏東縣  滿州鄉      佳樂水  24.1       75       0.0\n",
       "2016-04-18  臺南市  白河區       白河  23.4       68       0.0\n",
       "2016-04-19  新竹縣  峨眉鄉       峨眉  16.6       73       5.5\n",
       "2016-04-20  新北市  蘆洲區       蘆洲  17.6       71     -99.0\n",
       "2016-04-21  屏東縣  萬巒鄉       來義  26.8       69       0.0\n",
       "2016-04-22  新北市  三重區       三重  16.3       76       3.5\n",
       "2016-04-23  高雄市  茄萣區       興達  25.1       67       0.0\n",
       "2016-04-24  新北市  板橋區       板橋  15.6       73       5.0\n",
       "2016-04-26  花蓮縣  壽豐鄉       大坑  15.7       94       0.0\n",
       "2016-04-27  新竹縣  五峰鄉       雪霸  15.7       62       0.0\n",
       "\n",
       "[367 rows x 6 columns]"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 查询最高温度小于30度，最低温度大于15度的天气数据\n",
    "df.loc[(df[\"气温(度)\"].astype(float)<30) & (df[\"气温(度)\"].astype(float)>15),:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "日期\n",
       "2015-01-01    False\n",
       "2015-01-02     True\n",
       "2015-01-03     True\n",
       "2015-01-04    False\n",
       "2015-01-05    False\n",
       "2015-01-06     True\n",
       "2015-01-07     True\n",
       "2015-01-08     True\n",
       "2015-01-09    False\n",
       "2015-01-10    False\n",
       "2015-01-11     True\n",
       "2015-01-12     True\n",
       "2015-01-13     True\n",
       "2015-01-14     True\n",
       "2015-01-15     True\n",
       "2015-01-16    False\n",
       "2015-01-17    False\n",
       "2015-01-18     True\n",
       "2015-01-19     True\n",
       "2015-01-20     True\n",
       "2015-01-21     True\n",
       "2015-01-22    False\n",
       "2015-01-23     True\n",
       "2015-01-24     True\n",
       "2015-01-25    False\n",
       "2015-01-26     True\n",
       "2015-01-27     True\n",
       "2015-01-28     True\n",
       "2015-01-29     True\n",
       "2015-01-30    False\n",
       "              ...  \n",
       "2016-03-30     True\n",
       "2016-03-31     True\n",
       "2016-04-01     True\n",
       "2016-04-02     True\n",
       "2016-04-03     True\n",
       "2016-04-04     True\n",
       "2016-04-05     True\n",
       "2016-04-06     True\n",
       "2016-04-07     True\n",
       "2016-04-08    False\n",
       "2016-04-09    False\n",
       "2016-04-10     True\n",
       "2016-04-11     True\n",
       "2016-04-12     True\n",
       "2016-04-13     True\n",
       "2016-04-14     True\n",
       "2016-04-15    False\n",
       "2016-04-16     True\n",
       "2016-04-17     True\n",
       "2016-04-18     True\n",
       "2016-04-19     True\n",
       "2016-04-20     True\n",
       "2016-04-21     True\n",
       "2016-04-22     True\n",
       "2016-04-23     True\n",
       "2016-04-24     True\n",
       "2016-04-25    False\n",
       "2016-04-26     True\n",
       "2016-04-27     True\n",
       "2016-04-28    False\n",
       "Name: 气温(度), Length: 484, dtype: bool"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 再次观察这里的boolean条件\n",
    "(df[\"气温(度)\"].astype(float)<30) & (df[\"气温(度)\"].astype(float)>15)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 5. 调用函数查询"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>城市</th>\n",
       "      <th>行政区</th>\n",
       "      <th>观测站</th>\n",
       "      <th>气温(度)</th>\n",
       "      <th>相对湿度(%)</th>\n",
       "      <th>累积雨量(mm)</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>日期</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2015-01-02</th>\n",
       "      <td>臺南市</td>\n",
       "      <td>安平區</td>\n",
       "      <td>安平</td>\n",
       "      <td>23.5</td>\n",
       "      <td>70</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-03</th>\n",
       "      <td>臺東縣</td>\n",
       "      <td>東河鄉</td>\n",
       "      <td>七塊厝</td>\n",
       "      <td>19.6</td>\n",
       "      <td>86</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-06</th>\n",
       "      <td>嘉義縣</td>\n",
       "      <td>大林鎮</td>\n",
       "      <td>大林</td>\n",
       "      <td>23.2</td>\n",
       "      <td>63</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-07</th>\n",
       "      <td>花蓮縣</td>\n",
       "      <td>玉里鎮</td>\n",
       "      <td>玉里</td>\n",
       "      <td>18.5</td>\n",
       "      <td>85</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-08</th>\n",
       "      <td>嘉義市</td>\n",
       "      <td>東區</td>\n",
       "      <td>嘉義市東區</td>\n",
       "      <td>25</td>\n",
       "      <td>64</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-11</th>\n",
       "      <td>彰化縣</td>\n",
       "      <td>大城鄉</td>\n",
       "      <td>三豐</td>\n",
       "      <td>17.4</td>\n",
       "      <td>81</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-12</th>\n",
       "      <td>雲林縣</td>\n",
       "      <td>斗六市</td>\n",
       "      <td>斗六</td>\n",
       "      <td>23</td>\n",
       "      <td>58</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-13</th>\n",
       "      <td>南投縣</td>\n",
       "      <td>魚池鄉</td>\n",
       "      <td>魚池</td>\n",
       "      <td>26.3</td>\n",
       "      <td>50</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-14</th>\n",
       "      <td>臺東縣</td>\n",
       "      <td>海端鄉</td>\n",
       "      <td>向陽</td>\n",
       "      <td>16.3</td>\n",
       "      <td>71</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-15</th>\n",
       "      <td>屏東縣</td>\n",
       "      <td>竹田鄉</td>\n",
       "      <td>竹田</td>\n",
       "      <td>26.7</td>\n",
       "      <td>80</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-18</th>\n",
       "      <td>苗栗縣</td>\n",
       "      <td>頭屋鄉</td>\n",
       "      <td>明德</td>\n",
       "      <td>17</td>\n",
       "      <td>65</td>\n",
       "      <td>-99.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-19</th>\n",
       "      <td>臺南市</td>\n",
       "      <td>下營區</td>\n",
       "      <td>下營</td>\n",
       "      <td>26.2</td>\n",
       "      <td>58</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-20</th>\n",
       "      <td>屏東縣</td>\n",
       "      <td>萬丹鄉</td>\n",
       "      <td>萬丹</td>\n",
       "      <td>27</td>\n",
       "      <td>62</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-21</th>\n",
       "      <td>新北市</td>\n",
       "      <td>三峽區</td>\n",
       "      <td>三峽</td>\n",
       "      <td>16.5</td>\n",
       "      <td>67</td>\n",
       "      <td>-99.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-23</th>\n",
       "      <td>彰化縣</td>\n",
       "      <td>大城鄉</td>\n",
       "      <td>大城</td>\n",
       "      <td>19.2</td>\n",
       "      <td>72</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-24</th>\n",
       "      <td>臺中市</td>\n",
       "      <td>大里區</td>\n",
       "      <td>大里</td>\n",
       "      <td>24.3</td>\n",
       "      <td>50</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-26</th>\n",
       "      <td>臺東縣</td>\n",
       "      <td>鹿野鄉</td>\n",
       "      <td>鹿野</td>\n",
       "      <td>18.2</td>\n",
       "      <td>85</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-27</th>\n",
       "      <td>嘉義縣</td>\n",
       "      <td>太保市</td>\n",
       "      <td>太保</td>\n",
       "      <td>23.9</td>\n",
       "      <td>61</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-28</th>\n",
       "      <td>臺南市</td>\n",
       "      <td>學甲區</td>\n",
       "      <td>學甲</td>\n",
       "      <td>22.2</td>\n",
       "      <td>66</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-29</th>\n",
       "      <td>屏東縣</td>\n",
       "      <td>新園鄉</td>\n",
       "      <td>新園</td>\n",
       "      <td>25.4</td>\n",
       "      <td>76</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-31</th>\n",
       "      <td>臺中市</td>\n",
       "      <td>清水區</td>\n",
       "      <td>清水</td>\n",
       "      <td>17.8</td>\n",
       "      <td>80</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-02-01</th>\n",
       "      <td>臺南市</td>\n",
       "      <td>新化區</td>\n",
       "      <td>虎頭埤</td>\n",
       "      <td>26.1</td>\n",
       "      <td>67</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-02-02</th>\n",
       "      <td>臺中市</td>\n",
       "      <td>石岡區</td>\n",
       "      <td>石岡</td>\n",
       "      <td>19.4</td>\n",
       "      <td>99</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-02-03</th>\n",
       "      <td>屏東縣</td>\n",
       "      <td>枋山鄉</td>\n",
       "      <td>枋山</td>\n",
       "      <td>25.1</td>\n",
       "      <td>67</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-02-04</th>\n",
       "      <td>屏東縣</td>\n",
       "      <td>滿州鄉</td>\n",
       "      <td>滿州</td>\n",
       "      <td>22.6</td>\n",
       "      <td>79</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-02-05</th>\n",
       "      <td>屏東縣</td>\n",
       "      <td>恆春鎮</td>\n",
       "      <td>墾雷</td>\n",
       "      <td>23.6</td>\n",
       "      <td>82</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-02-07</th>\n",
       "      <td>臺東縣</td>\n",
       "      <td>卑南鄉</td>\n",
       "      <td>檳榔四格山</td>\n",
       "      <td>18.8</td>\n",
       "      <td>88</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-02-08</th>\n",
       "      <td>嘉義縣</td>\n",
       "      <td>六腳鄉</td>\n",
       "      <td>六腳</td>\n",
       "      <td>22.3</td>\n",
       "      <td>67</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-02-09</th>\n",
       "      <td>雲林縣</td>\n",
       "      <td>斗南鎮</td>\n",
       "      <td>斗南</td>\n",
       "      <td>22.5</td>\n",
       "      <td>64</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-02-10</th>\n",
       "      <td>臺南市</td>\n",
       "      <td>北區</td>\n",
       "      <td>臺南市北區</td>\n",
       "      <td>24.7</td>\n",
       "      <td>66</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-03-23</th>\n",
       "      <td>雲林縣</td>\n",
       "      <td>水林鄉</td>\n",
       "      <td>水林</td>\n",
       "      <td>20.9</td>\n",
       "      <td>69</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-03-25</th>\n",
       "      <td>高雄市</td>\n",
       "      <td>茄萣區</td>\n",
       "      <td>茄萣</td>\n",
       "      <td>23.1</td>\n",
       "      <td>76</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-03-26</th>\n",
       "      <td>宜蘭縣</td>\n",
       "      <td>冬山鄉</td>\n",
       "      <td>冬山</td>\n",
       "      <td>17</td>\n",
       "      <td>93</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-03-27</th>\n",
       "      <td>宜蘭縣</td>\n",
       "      <td>礁溪鄉</td>\n",
       "      <td>礁溪</td>\n",
       "      <td>17.6</td>\n",
       "      <td>71</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-03-28</th>\n",
       "      <td>屏東縣</td>\n",
       "      <td>里港鄉</td>\n",
       "      <td>里港</td>\n",
       "      <td>27.8</td>\n",
       "      <td>66</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-03-30</th>\n",
       "      <td>臺南市</td>\n",
       "      <td>白河區</td>\n",
       "      <td>鹿寮</td>\n",
       "      <td>23</td>\n",
       "      <td>74</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-03-31</th>\n",
       "      <td>宜蘭縣</td>\n",
       "      <td>壯圍鄉</td>\n",
       "      <td>大福</td>\n",
       "      <td>17.3</td>\n",
       "      <td>79</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-04-01</th>\n",
       "      <td>臺東縣</td>\n",
       "      <td>達仁鄉</td>\n",
       "      <td>達仁林場</td>\n",
       "      <td>17.9</td>\n",
       "      <td>97</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-04-02</th>\n",
       "      <td>雲林縣</td>\n",
       "      <td>東勢鄉</td>\n",
       "      <td>雲林東勢</td>\n",
       "      <td>19.9</td>\n",
       "      <td>71</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-04-03</th>\n",
       "      <td>屏東縣</td>\n",
       "      <td>牡丹鄉</td>\n",
       "      <td>四林格山</td>\n",
       "      <td>19.2</td>\n",
       "      <td>94</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-04-04</th>\n",
       "      <td>屏東縣</td>\n",
       "      <td>牡丹鄉</td>\n",
       "      <td>牡丹</td>\n",
       "      <td>22.8</td>\n",
       "      <td>79</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-04-05</th>\n",
       "      <td>嘉義縣</td>\n",
       "      <td>布袋鎮</td>\n",
       "      <td>布袋</td>\n",
       "      <td>21.4</td>\n",
       "      <td>69</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-04-06</th>\n",
       "      <td>南投縣</td>\n",
       "      <td>竹山鎮</td>\n",
       "      <td>竹山</td>\n",
       "      <td>24.6</td>\n",
       "      <td>66</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-04-07</th>\n",
       "      <td>高雄市</td>\n",
       "      <td>田寮區</td>\n",
       "      <td>古亭坑</td>\n",
       "      <td>26.4</td>\n",
       "      <td>67</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-04-10</th>\n",
       "      <td>屏東縣</td>\n",
       "      <td>鹽埔鄉</td>\n",
       "      <td>鹽埔</td>\n",
       "      <td>28.3</td>\n",
       "      <td>73</td>\n",
       "      <td>-99.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-04-11</th>\n",
       "      <td>臺東縣</td>\n",
       "      <td>臺東市</td>\n",
       "      <td>知本(水試所)</td>\n",
       "      <td>22.7</td>\n",
       "      <td>72</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-04-12</th>\n",
       "      <td>南投縣</td>\n",
       "      <td>中寮鄉</td>\n",
       "      <td>中寮</td>\n",
       "      <td>24.2</td>\n",
       "      <td>59</td>\n",
       "      <td>-99.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-04-13</th>\n",
       "      <td>臺南市</td>\n",
       "      <td>龍崎區</td>\n",
       "      <td>崎頂</td>\n",
       "      <td>25.1</td>\n",
       "      <td>75</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-04-14</th>\n",
       "      <td>苗栗縣</td>\n",
       "      <td>三義鄉</td>\n",
       "      <td>三義</td>\n",
       "      <td>15.3</td>\n",
       "      <td>91</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-04-16</th>\n",
       "      <td>屏東縣</td>\n",
       "      <td>來義鄉</td>\n",
       "      <td>白鷺</td>\n",
       "      <td>25.3</td>\n",
       "      <td>72</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-04-17</th>\n",
       "      <td>屏東縣</td>\n",
       "      <td>滿州鄉</td>\n",
       "      <td>佳樂水</td>\n",
       "      <td>24.1</td>\n",
       "      <td>75</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-04-18</th>\n",
       "      <td>臺南市</td>\n",
       "      <td>白河區</td>\n",
       "      <td>白河</td>\n",
       "      <td>23.4</td>\n",
       "      <td>68</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-04-19</th>\n",
       "      <td>新竹縣</td>\n",
       "      <td>峨眉鄉</td>\n",
       "      <td>峨眉</td>\n",
       "      <td>16.6</td>\n",
       "      <td>73</td>\n",
       "      <td>5.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-04-20</th>\n",
       "      <td>新北市</td>\n",
       "      <td>蘆洲區</td>\n",
       "      <td>蘆洲</td>\n",
       "      <td>17.6</td>\n",
       "      <td>71</td>\n",
       "      <td>-99.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-04-21</th>\n",
       "      <td>屏東縣</td>\n",
       "      <td>萬巒鄉</td>\n",
       "      <td>來義</td>\n",
       "      <td>26.8</td>\n",
       "      <td>69</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-04-22</th>\n",
       "      <td>新北市</td>\n",
       "      <td>三重區</td>\n",
       "      <td>三重</td>\n",
       "      <td>16.3</td>\n",
       "      <td>76</td>\n",
       "      <td>3.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-04-23</th>\n",
       "      <td>高雄市</td>\n",
       "      <td>茄萣區</td>\n",
       "      <td>興達</td>\n",
       "      <td>25.1</td>\n",
       "      <td>67</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-04-24</th>\n",
       "      <td>新北市</td>\n",
       "      <td>板橋區</td>\n",
       "      <td>板橋</td>\n",
       "      <td>15.6</td>\n",
       "      <td>73</td>\n",
       "      <td>5.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-04-26</th>\n",
       "      <td>花蓮縣</td>\n",
       "      <td>壽豐鄉</td>\n",
       "      <td>大坑</td>\n",
       "      <td>15.7</td>\n",
       "      <td>94</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-04-27</th>\n",
       "      <td>新竹縣</td>\n",
       "      <td>五峰鄉</td>\n",
       "      <td>雪霸</td>\n",
       "      <td>15.7</td>\n",
       "      <td>62</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>367 rows × 6 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "             城市  行政区      观测站 气温(度)  相对湿度(%)  累积雨量(mm)\n",
       "日期                                                    \n",
       "2015-01-02  臺南市  安平區       安平  23.5       70       0.0\n",
       "2015-01-03  臺東縣  東河鄉      七塊厝  19.6       86       0.0\n",
       "2015-01-06  嘉義縣  大林鎮       大林  23.2       63       0.0\n",
       "2015-01-07  花蓮縣  玉里鎮       玉里  18.5       85       0.0\n",
       "2015-01-08  嘉義市   東區    嘉義市東區    25       64       0.0\n",
       "2015-01-11  彰化縣  大城鄉       三豐  17.4       81       0.0\n",
       "2015-01-12  雲林縣  斗六市       斗六    23       58       0.0\n",
       "2015-01-13  南投縣  魚池鄉       魚池  26.3       50       0.0\n",
       "2015-01-14  臺東縣  海端鄉       向陽  16.3       71       0.0\n",
       "2015-01-15  屏東縣  竹田鄉       竹田  26.7       80       0.0\n",
       "2015-01-18  苗栗縣  頭屋鄉       明德    17       65     -99.0\n",
       "2015-01-19  臺南市  下營區       下營  26.2       58       0.0\n",
       "2015-01-20  屏東縣  萬丹鄉       萬丹    27       62       0.0\n",
       "2015-01-21  新北市  三峽區       三峽  16.5       67     -99.0\n",
       "2015-01-23  彰化縣  大城鄉       大城  19.2       72       0.0\n",
       "2015-01-24  臺中市  大里區       大里  24.3       50       0.0\n",
       "2015-01-26  臺東縣  鹿野鄉       鹿野  18.2       85       0.0\n",
       "2015-01-27  嘉義縣  太保市       太保  23.9       61       0.0\n",
       "2015-01-28  臺南市  學甲區       學甲  22.2       66       0.0\n",
       "2015-01-29  屏東縣  新園鄉       新園  25.4       76       0.0\n",
       "2015-01-31  臺中市  清水區       清水  17.8       80       0.0\n",
       "2015-02-01  臺南市  新化區      虎頭埤  26.1       67       0.0\n",
       "2015-02-02  臺中市  石岡區       石岡  19.4       99       0.0\n",
       "2015-02-03  屏東縣  枋山鄉       枋山  25.1       67       0.0\n",
       "2015-02-04  屏東縣  滿州鄉       滿州  22.6       79       0.0\n",
       "2015-02-05  屏東縣  恆春鎮       墾雷  23.6       82       0.0\n",
       "2015-02-07  臺東縣  卑南鄉    檳榔四格山  18.8       88       0.0\n",
       "2015-02-08  嘉義縣  六腳鄉       六腳  22.3       67       0.0\n",
       "2015-02-09  雲林縣  斗南鎮       斗南  22.5       64       0.0\n",
       "2015-02-10  臺南市   北區    臺南市北區  24.7       66       0.0\n",
       "...         ...  ...      ...   ...      ...       ...\n",
       "2016-03-23  雲林縣  水林鄉       水林  20.9       69       0.0\n",
       "2016-03-25  高雄市  茄萣區       茄萣  23.1       76       0.0\n",
       "2016-03-26  宜蘭縣  冬山鄉       冬山    17       93       0.0\n",
       "2016-03-27  宜蘭縣  礁溪鄉       礁溪  17.6       71       0.0\n",
       "2016-03-28  屏東縣  里港鄉       里港  27.8       66       0.0\n",
       "2016-03-30  臺南市  白河區       鹿寮    23       74       0.0\n",
       "2016-03-31  宜蘭縣  壯圍鄉       大福  17.3       79       0.0\n",
       "2016-04-01  臺東縣  達仁鄉     達仁林場  17.9       97       0.0\n",
       "2016-04-02  雲林縣  東勢鄉     雲林東勢  19.9       71       0.0\n",
       "2016-04-03  屏東縣  牡丹鄉     四林格山  19.2       94       0.0\n",
       "2016-04-04  屏東縣  牡丹鄉       牡丹  22.8       79       0.0\n",
       "2016-04-05  嘉義縣  布袋鎮       布袋  21.4       69       0.0\n",
       "2016-04-06  南投縣  竹山鎮       竹山  24.6       66       0.0\n",
       "2016-04-07  高雄市  田寮區      古亭坑  26.4       67       0.0\n",
       "2016-04-10  屏東縣  鹽埔鄉       鹽埔  28.3       73     -99.0\n",
       "2016-04-11  臺東縣  臺東市  知本(水試所)  22.7       72       0.0\n",
       "2016-04-12  南投縣  中寮鄉       中寮  24.2       59     -99.0\n",
       "2016-04-13  臺南市  龍崎區       崎頂  25.1       75       0.0\n",
       "2016-04-14  苗栗縣  三義鄉       三義  15.3       91       2.0\n",
       "2016-04-16  屏東縣  來義鄉       白鷺  25.3       72       0.0\n",
       "2016-04-17  屏東縣  滿州鄉      佳樂水  24.1       75       0.0\n",
       "2016-04-18  臺南市  白河區       白河  23.4       68       0.0\n",
       "2016-04-19  新竹縣  峨眉鄉       峨眉  16.6       73       5.5\n",
       "2016-04-20  新北市  蘆洲區       蘆洲  17.6       71     -99.0\n",
       "2016-04-21  屏東縣  萬巒鄉       來義  26.8       69       0.0\n",
       "2016-04-22  新北市  三重區       三重  16.3       76       3.5\n",
       "2016-04-23  高雄市  茄萣區       興達  25.1       67       0.0\n",
       "2016-04-24  新北市  板橋區       板橋  15.6       73       5.0\n",
       "2016-04-26  花蓮縣  壽豐鄉       大坑  15.7       94       0.0\n",
       "2016-04-27  新竹縣  五峰鄉       雪霸  15.7       62       0.0\n",
       "\n",
       "[367 rows x 6 columns]"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 直接写lambda表达式\n",
    "df.loc[lambda df : (df[\"气温(度)\"].astype(float)<30) & (df[\"气温(度)\"].astype(float)>15),:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "日期\n",
       "2015-01-01     True\n",
       "2015-01-02     True\n",
       "2015-01-03     True\n",
       "2015-01-04    False\n",
       "2015-01-05     True\n",
       "2015-01-06     True\n",
       "2015-01-07     True\n",
       "2015-01-08     True\n",
       "2015-01-09    False\n",
       "2015-01-10    False\n",
       "2015-01-11     True\n",
       "2015-01-12     True\n",
       "2015-01-13     True\n",
       "2015-01-14     True\n",
       "2015-01-15     True\n",
       "2015-01-16    False\n",
       "2015-01-17    False\n",
       "2015-01-18    False\n",
       "2015-01-19     True\n",
       "2015-01-20     True\n",
       "2015-01-21    False\n",
       "2015-01-22    False\n",
       "2015-01-23     True\n",
       "2015-01-24     True\n",
       "2015-01-25    False\n",
       "2015-01-26     True\n",
       "2015-01-27     True\n",
       "2015-01-28     True\n",
       "2015-01-29     True\n",
       "2015-01-30    False\n",
       "              ...  \n",
       "2016-03-30     True\n",
       "2016-03-31     True\n",
       "2016-04-01     True\n",
       "2016-04-02     True\n",
       "2016-04-03     True\n",
       "2016-04-04     True\n",
       "2016-04-05     True\n",
       "2016-04-06     True\n",
       "2016-04-07     True\n",
       "2016-04-08    False\n",
       "2016-04-09     True\n",
       "2016-04-10    False\n",
       "2016-04-11     True\n",
       "2016-04-12    False\n",
       "2016-04-13     True\n",
       "2016-04-14    False\n",
       "2016-04-15    False\n",
       "2016-04-16     True\n",
       "2016-04-17     True\n",
       "2016-04-18     True\n",
       "2016-04-19    False\n",
       "2016-04-20    False\n",
       "2016-04-21     True\n",
       "2016-04-22    False\n",
       "2016-04-23     True\n",
       "2016-04-24    False\n",
       "2016-04-25     True\n",
       "2016-04-26     True\n",
       "2016-04-27     True\n",
       "2016-04-28    False\n",
       "Name: 累积雨量(mm), Length: 484, dtype: bool"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[\"累积雨量(mm)\"]==0.0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>城市</th>\n",
       "      <th>行政区</th>\n",
       "      <th>观测站</th>\n",
       "      <th>气温(度)</th>\n",
       "      <th>相对湿度(%)</th>\n",
       "      <th>累积雨量(mm)</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>日期</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "Empty DataFrame\n",
       "Columns: [城市, 行政区, 观测站, 气温(度), 相对湿度(%), 累积雨量(mm)]\n",
       "Index: []"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#函数式编程的本质：\n",
    "#    函数自身可以像变量一样传递\n",
    "\n",
    "# 编写自己的函数，查询九月份累计雨量为0的数据\n",
    "def query_my_data(df):\n",
    "    return (df.index.str.startswith(\"2015-9\")) & (df[\"累积雨量(mm)\"]== 0.0)\n",
    "\n",
    "df.loc[query_my_data,:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
